﻿@model IEnumerable<PurchaseOrderInstallmentItem>

@{
    var poInstallId = ViewBag.PoInstallId as int? ?? 0;
    var poId = ViewBag.PoId as int? ?? 0;
    var bidderQuotation = ViewBag.BidderQuotation as BidderQuotation;
    var poInstall = ViewBag.PoInstall as PurchaseOrderInstallment;
}

@{
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
    using (Html.BeginForm("DeleteAll", "Installment", FormMethod.Post))
    {
        @Html.AntiForgeryToken()
        @Html.Hidden("HeaderPoId", poInstallId)
    
        <div class="row-fluid">
            
            @if (ViewBag.ErrorMessage != null)
            {
                <div class="alert alert-block alert-error">@ViewBag.ErrorMessage</div>
            }

            <div class="block-button-menu-above">
                @Html.ActionLink("เพิ่ม", "Create", new {HeaderPoId = poId}, new {@class = "btn btn-small btn-success button-standard-width", role = "button"})
                @Html.ButtonDeleteAll()
            </div>

            <div class="alert-error">@Html.ValidationSummary()</div>
            <div class="row-fluid">
                <div class="table-header span12">
                    <div class="span10">สินค้า/บริการ</div>
                    @Html.Partial("_ExportButton")
                </div>
            </div>

            <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
                <thead>
                    <tr>
                        <th class="center" style="width: 50px;"><label><input type="checkbox" /><span class="lbl"></span></label></th>
                        <th class="center">เลขที่งวด</th>
                        <th class="center">ราคารวม Vat (บาท)</th>
                        <th class="center">จำนวน</th>                    
                        <th class="center">Vat (บาท)</th>        
                        <th class="center">ราคาสุทธิ (บาท)</th>
                        @*<th class="center" style="width: 80px;">&nbsp;</th>*@
                    </tr>
                </thead>
                <tbody>                
                    @foreach (var m in Model)
                        {
                            <tr>
                                <td class="center">
                                    <label><input type="checkbox" name="deleteIds" value="@(m.PoInstallItemId)" /><span class="lbl"></span></label>
                                </td>
                                <td>
                                    @(poInstall ==null ? null : poInstall.InstallNumber)
                                </td> 
                                <td>
                                    @m.ItemPriceIncludeVat.Value.ToString("#,##0.00")
                                </td> 
                                <td>
                                    @m.Qty 
                                </td> 
                                <td>
                                    @m.VatAmount.Value.ToString("#,##0.00")
                                </td> 
                                <td>
                                    @m.NetAmount.Value.ToString("#,##0.00")
                                </td> 
                            </tr>
                        } 
                </tbody>
            </table>
        </div>
    }
}

@section scripts {
    
    <script type="text/javascript">
        $(function() {
            var oTable1 = $('#table').dataTable({
                "aoColumns": [
                    { "bSortable": false },null,null,null,null,{ "bSortable": false }
                ]
            });

            $('table th input:checkbox').on('click', function() {
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                    .each(function() {
                        this.checked = that.checked;
                        $(this).closest('tr').toggleClass('selected');
                    });
            });

            $('[data-rel=tooltip]').tooltip();

            $("form").submit(function() {
                var currentForm = this;
                bootbox.confirm(function(result) {
                    var _result = result;
                    if (result) {
                        $.ajax({
                            url: "@Url.Action("DeleteAll")",
                            type: "post",
                            dataType: "json",
                            data: $(currentForm).serialize(),
                            success: function(result2) {
                                if (result2.success) {
                                    location.reload();
                                    $("#message").html(result2.message);
                                } else {
                                    $("#message").html(result2.message);
                                }
                            }
                        });
                    }
                });
                return false;
            });
        })
    </script>
}